<template>
	<view>
		<mian-index ref="childer" @send="getSonValue"></mian-index>
		<button v-if="sonvalue.isVerified&&sonvalue.isVerified==1" @click="editor"
			class="arc_button btn_appointment">实名认证</button>
		<button class="btn_appointment arc_button" type="default" @click="last">下一步</button>
	</view>
</template>

<script>
	import {
		childer
	} from '@/pagesSub/components/ofPatient.vue'
	import {
		patientList,
		doctorList
	} from '@/api/prescribing.js';
	import {
		undoneConsult
	} from '@/api/user.js';
	import {
		hasPressDrug, //药品列表是否有处方药
	} from '@/pagesSub-Five/api/index.js';
	import store from '@/store';
	export default {
		components: {
			'mian-index': childer
		},
		data() {
			return {
				info: [],
				choosePeopleInfo: [],
				sonvalue: {},
				queryParams: {
					pageNum: 1,
					pageSize: 10,
				},
				medicals: [],
				typeStatus: {
					1: "图文咨询",
					2: "用药咨询",
					3: "免费咨询",
				},
				type: 0
			}
		},
		onLoad: function(option) {
			if (option.medicals) {
				let medical = JSON.parse(decodeURIComponent(option.medicals));
				this.medicals = medical;
				// console.log(medical, '接收到的数据999----')
			}
		},
		onShow() {
			this.$refs.childer.patientListInfo();
			this.$refs.childer.peopleNumber();
			this.sonvalue = {};
		},
		methods: {
			getSonValue: function(res) {
				this.sonvalue = res;
				// console.log("*******sonvalue",JSON.stringify(this.sonvalue))
			},
			patientListInfo() {
				let _this = this
				uni.showLoading({
					title: '加载中'
				})
				patientList(_this.queryParams).then(res => {
					_this.info = res.rows;
					uni.hideLoading()
				}).catch(res => {
					uni.hideLoading()
				});
			},
			doctorLists() {
				let _this = this
				uni.showLoading({
					title: '加载中'
				})
				doctorList(_this.queryParams).then(res => {
					// _this.info=res.rows;
					uni.hideLoading()
				}).catch(res => {
					uni.hideLoading()
				});
			},
			// 下一步
			last() {
				if (this.sonvalue && this.sonvalue.isVerified == 0) {
					let items = encodeURIComponent(JSON.stringify(this.sonvalue))
					let medicals = encodeURIComponent(JSON.stringify(this.medicals))
					// console.log(this.sonvalue, this.medicals, '777--')
					// 判断用户购买药品是否为处方药
					hasPressDrug({
							productList: this.medicals, //药品列表
						}).then((res) => {
							// flag=1 存在处方药 跳转580 其余都不跳转
							if (res.data.flag == 1) {
								// 购买的药品为处方药，跳转580页面
								// drugState是否为中药  ture=中药 false=西医
								// patientID=就诊人id  productList=购买药品列表 phone=就诊人手机号(用于下级页面判断上次问诊是否结束)
								uni.redirectTo({
									url: `/pagesSub-Five/index/index?patientID=${this.sonvalue.patientId}
							&productList=${medicals}&drugState=false&phone=${this.sonvalue.phone}`
								})
							} else {
								// 购买的药品不是处方药， 跳转支付页面
								uni.redirectTo({
									url: `./mallorder?item=${items}&medicals=${medicals}`
								})
							}
						})
						.catch((err) => {
							uni.showToast({
								title: err,
								icon: 'none',
								duration: 3000,
							});
						});
					// console.log("*****",JSON.stringify(medical))
				} else {
					uni.showToast({
						title: "请选择就诊人",
						icon: 'none',
						duration: 3000
					})
				}
				if (this.sonvalue.isVerified == 1) {
					uni.showToast({
						title: "该就诊人未实名，请去实名",
						icon: 'none',
						duration: 3000
					})
					return;
				}

			},
			choosePeople(data) {
				this.choosePeopleInfo = data;
			},
			editor() {
				uni.navigateTo({
					url: `/pagesSub-My/my/editPatients?patientId=${this.sonvalue.patientId}`
				})
			},
		}
	}
</script>

<style scoped>
	.content {
		padding: 10rpx;
		display: flex;
		flex-wrap: wrap;
	}

	.content view {
		/* width: 150rpx; */
		margin-left: 10rpx;
		padding: 10rpx;
		background-color: #FFFFFF;
		border-radius: 10rpx;
		/* margin-right: 20rpx; */
		margin-bottom: 20rpx;
	}

	.introduce {
		font-size: 29rpx;
	}

	.introduce text {
		margin-right: 20rpx;
	}

	.btn_appointment {
		margin-top: 40rpx;
		background: -webkit-linear-gradient(#77E2A4, #4CCDBC);
		color: #FFFFFF;
	}
</style>